﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.IO;
using System.Reflection;
using System.Web.Routing;
using MvcEngine.Mvc.Models.ViewModels;
using MvcEngine.Core.Validation;

namespace MvcEngine.Mvc.UI
{
    public class ValidationViewItem
    {
        protected string name;
        protected List<FieldValidatorAttribute> validators = new List<FieldValidatorAttribute>();


        public ValidationViewItem(string name)
        {
            this.name = name;
        }

        public List<FieldValidatorAttribute> Validators
        {
            get 
            { 
                return validators; 
            }
        }

        public string Name
        {
            get
            {
                return name;
            }
        }

        public ValidationViewItem SetName(string name)
        {
            this.name = name;
            return this;
        }

        public ValidationViewItem AddValidators(IEnumerable<FieldValidatorAttribute> vals) 
        {
            validators.AddRange(vals);
            return this;        
        }

        public ValidationViewItem AddValidator(FieldValidatorAttribute validator)
        {
            validators.Add(validator);
            return this;
        }

        public ValidationViewItem RequiredValidator()
        {
            validators.Add(new RequiredFieldValidatorAttribute("$RequiredValidator"));
            return this;
        }

        public ValidationViewItem RequiredValidator(string message)
        {
            validators.Add(new RequiredFieldValidatorAttribute(message));
            return this;
        }

        public ValidationViewItem LengthValidator(int minLength, int maxLength) 
        {
            validators.Add(new LengthValidatorAttribute("$LengthValidator", minLength, maxLength));
            return this;
        }

        public ValidationViewItem LengthValidator(int minLength, int maxLength, string message)
        {
            validators.Add(new LengthValidatorAttribute(message, minLength, maxLength));
            return this;
        }
    }
}
